package com.nbsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbsystem.entity.ElcInfotype;
import com.nbsystem.entity.SysUser;
import com.nbsystem.service.ElcInfotypeService;
import com.nbsystem.service.SysUserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (SysUser)表控制层
 *
 * @author makejava
 * @since 2021-06-01 09:12:26
 */
@RestController
@RequestMapping("sysUser")
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;


    /**
     * 服务对象
     */
    @Resource
    private ElcInfotypeService elcInfotypeService;

//数据展示
//模糊查询
    @RequestMapping("list")
    public PageInfo<SysUser> queryAll(SysUser sysUser,Integer rows,Integer page) {
        PageHelper.startPage(page,rows);
        List<SysUser> list = sysUserService.queryAll(sysUser);
        PageInfo<SysUser> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }



    @RequestMapping("goBack")
    public PageInfo<SysUser> goBack(SysUser sysUser,Integer rows,Integer page) {
        PageHelper.startPage(page,rows);
        List<SysUser> list = sysUserService.goBack(sysUser);
        PageInfo<SysUser> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    @RequestMapping("queryAll")
    public List<SysUser> query(SysUser sysUser) {
        List<SysUser> list = sysUserService.goBack(sysUser);
        return list;
    }
    /*
    添加角色信息
     */
    @RequestMapping("add")
    public String addSysUser(SysUser sysUser){
        sysUser.setCreateTime(new Date());
        sysUser.setUpdateTime(new Date());
        sysUser.setLocked(0);
        sysUserService.insert(sysUser);
        return "success";
    }


    /*
    通过id查询数据
     */
    @RequestMapping("query/{id}")
    public SysUser querySysUser(@PathVariable Integer id){
        SysUser sysUser = sysUserService.queryById(id);
        return sysUser;
    }


    /*
    修改用户信息
     */
    @RequestMapping("update")
    public String updateSysUser(SysUser sysUser){
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return "success";
    }

    /*
    删除用户信息
     */
    @RequestMapping("delete/{id}")
    public  String deleteSysUser(@PathVariable Integer id){
        sysUserService.deleteById(id);
        return "success";
    }


    @RequestMapping("goBackById/{id}")
    public  String goBackSysUser(@PathVariable Integer id){
        sysUserService.goBackById(id);
        return "success";
    }


    @RequestMapping("deletes/{ids}")
    public String deleteSysUsers(@PathVariable Integer[] ids){
        sysUserService.deleteByIds(ids);
        return "success";
    }



    @RequestMapping("queryExl")
    public List<SysUser> queryAll(SysUser sysUser){
        return sysUserService.queryAll(sysUser);
    }


    @RequestMapping("user-role")
    public String userRole(){
        return "user/user-role";
    }

    @RequestMapping("queryInfo")
    public List<ElcInfotype> queryInfoTypeAlList (ElcInfotype erlcInfotype){
        return  this.elcInfotypeService.queryAll(erlcInfotype);
    }
}
